package com.jspxcms.common.util;

import com.jspxcms.core.domain.UserDetail;

import java.io.InputStream;
import java.util.Properties;

public class ScoreUtil {
    static {
        Properties prop = new Properties();
        try {
            InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("score.properties");
            prop.load(in);
            String levelScore = prop.getProperty("levelScore");
            String[] tmpScores = levelScore.split(",");
            int[] int_scores = new int[tmpScores.length];
            for (int i = 0; i < tmpScores.length; i++) {
                int_scores[i] = Integer.parseInt(tmpScores[i]);
            }
            scores = int_scores;
            String levelName = prop.getProperty("levelName");
            scoreLevels = levelName.split(",");
        } catch (Exception e) {
            e.printStackTrace();
        }
        property = prop;
    }

    public static Properties property;
    public static int[] scores;
    public static String[] scoreLevels;

    /**
     * @param userDetail
     * @return
     */
    public static String getLevelName(UserDetail userDetail) {
        if (userDetail == null)
            return null;
        return scoreLevels[Math.min(userDetail.getScoreLevel(), scoreLevels.length - 1)];
    }
}